package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Order;
import com.situ.mall.entity.OrderItem;
import com.situ.mall.entity.Product;
import com.situ.mall.mapper.OrderItemMapper;
import com.situ.mall.mapper.OrderMapper;
import com.situ.mall.mapper.ProductMapper;
import com.situ.mall.service.IOrderItemService;
import com.situ.mall.service.IOrderService;
import com.situ.mall.service.IProductService;

@Service
public class OrderServiceImpl implements IOrderService {
	@Autowired
	private OrderMapper orderMapper;

	@Override
	public List<Order> list() {
		return orderMapper.list();
	}
	@Override
	public ServerResponse pageList(Integer page, Integer limit) {
		// 1、使用PageHelper插件设置分页
		PageHelper.startPage(page, limit);
		// 2、执行查询
		List<Order> list = orderMapper.pageList();
		System.out.println("list = "+list);
		// 3、使用PageInfo对结果进行包装
		PageInfo pageInfo = new PageInfo(list);
		Integer count = (int) pageInfo.getTotal();// 得到总数量

		return ServerResponse.createSuccess("查询成功", count, list);

	}
	
	@Override
	public List<Order> selectByUserId(Integer userId) {
		
		return orderMapper.selectByUserId(userId);
	}
	
	@Override
	public ServerResponse deleteById(Integer id) {
		Integer count = orderMapper.deleteByPrimaryKey(id);
		System.out.println("count ="+count);
		if (count == 1) {
			return ServerResponse.createSuccess("删除成功");
		}else{
			return ServerResponse.createSuccess("删除失败");
		}
		
	}
}